package com.yxq.mdt.app.modules.socialcontact.ui.activity;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wuhenzhizao.titlebar.widget.CommonTitleBar;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.modules.socialcontact.adapter.SocialContactAllTopicsAdapter;
import com.yxq.mdt.app.modules.socialcontact.bean.SocialContactAllTopicsBean;
import com.yxq.mdt.app.modules.socialcontact.model.MainSocialContactModel;
import com.yxq.mdt.app.modules.socialcontact.presenter.MainSocialTopicsContract;
import com.yxq.mdt.app.modules.socialcontact.presenter.MainSocialTopicsPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 全部话题
 */
public class SocialContactAllTopicsAc extends BaseActivity<MainSocialTopicsPresenter> implements MainSocialTopicsContract.View {
    SocialContactAllTopicsAdapter socialContactAllTopicsAdapter;
    @BindView(R.id.titlebar)
    CommonTitleBar titlebar;
    @BindView(R.id.social_contact_recycler)
    RecyclerView socialContactRecycler;
    private List<SocialContactAllTopicsBean.DataBean> contactAllTopicsBeans;
    String isPublish, isPublishVoice, isPublishImage;

    @Override
    public int getLayoutId() {
        return R.layout.activity_all_topics_layout;
    }

    @Override
    public void initView() {
        isPublish = getIntent().getStringExtra("publish");
        isPublishVoice = getIntent().getStringExtra("publishVoice");
        isPublishImage = getIntent().getStringExtra("publishImage");
        contactAllTopicsBeans = new ArrayList<>();
        socialContactRecycler.setLayoutManager(new LinearLayoutManager(mActivity));
        socialContactAllTopicsAdapter = new SocialContactAllTopicsAdapter(R.layout.topics_all_list_item, contactAllTopicsBeans);
        socialContactRecycler.setAdapter(socialContactAllTopicsAdapter);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mPresenter = new MainSocialTopicsPresenter(this, new MainSocialContactModel());
        showLoadingDialog();
        mPresenter.getContactAllTopicsList();
    }

    @Override
    public void onContactAllTopicsSuccess(SocialContactAllTopicsBean socialContactAllTopicsBean) {
        hideLoadingDialog();
        if (socialContactAllTopicsBean == null) {
            return;
        }
        socialContactAllTopicsAdapter.setNewData(socialContactAllTopicsBean.getData());
        socialContactAllTopicsAdapter.setOnItemClickListener((adapter, view1, position) -> {
            Intent intent = new Intent();
            intent.putExtra("CircleName", "#" + socialContactAllTopicsBean.getData().get(position).getTagName() + "#");
            setResult(RESULT_OK, intent);
            finish();
        });
    }

    @Override
    public void onContactAllTopicsFailed() {
        hideLoadingDialog();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent();
        intent.putExtra("CircleName", "");
        setResult(RESULT_OK, intent);
        finish();
    }
}
